<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>在线考试平台</title>
    <link rel="shortcut icon" href="static/layui/images/exam.png" type="image/x-icon">
    <link rel="stylesheet" href="static/layui/css/font.css">
    <link rel="stylesheet" href="static/layui/css/xadmin.css">
    <script src="static/layui/lib/layui/layui.js"></script>
    <script src="static/layui/js/xadmin.js"></script>
    <script src="static/layui/js/jquery.min.js"></script>

</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-sm12 layui-col-md10 layui-col-md-offset1">
            <div class="layui-card">
                <div class="layui-card-header" style="background: #00F7DE">
                    <span style="float: left" id="e_name">
                    </span>
                </div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space15">
                        <div class="layui-col-sm12 layui-col-md6 layui-col-md-offset3">
                            <div class="layui-card">
                                <div class="layui-card-header" style="background: gainsboro">
                                    考试成绩
                                </div>
                                <div class="layui-card-header">
                                    单选题:<span id="cq_right_num"></span><span style="float: right" id="cq_score"></span>
                                </div>
                                <div class="layui-card-header">
                                    判断题:<span id="jq_right_num"></span><span style="float: right" id="jq_score"></span>
                                </div>
                                <div class="layui-card-header">
                                    填空题:<span id="fbq_right_num"></span><span style="float: right" id="fbq_score"></span>
                                </div>
                                <div class="layui-card-header">
                                    简答题:<span id="saq_right_num"></span><span style="float: right" id="saq_score"></span>
                                </div>
                                <div class="layui-card-header">
                                    总分:<span id="total_score"></span><span style="float: right" id="u_total_score"></span>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="layui-row layui-col-space15" id="question_list">

                    </div>

                </div>

            </div>
        </div>
    </div>
</div>

</body>

<script>
    layui.use(['element', "form", 'jquery', 'layer', 'util'], function () {
        const form = layui.form;
        const $ = layui.jquery;
        const layer = layui.layer;
        const element = layui.element;
        var util = layui.util;
        header(element)
        get_exam_result_by_eu_id();
        util.fixbar({
            top: true
            , css: {right: 15, bottom: 35}
            , bgcolor: '#2a96ff !important;display:block;'
            , showHeight: 100
            , click: function (type) {
                if (type === 'top') {
                    $('.layui-body').animate({//主要代码
                        scrollTop: 0
                    }, 200);
                }
            }
        });
    });

    function header(element) {
        var user_json = JSON.parse(sessionStorage.getItem("userJson"));
        var text = ""
        if (user_json === null) {
            location.href = '/exam_system/';
        } else {
            text += "<li class=\"layui-nav-item\">" +
                "                    <a href=\"javascript:;\">" + user_json.u_name + "</a>" +
                "                    <dl class=\"layui-nav-child\">" +
                "                        <dd><a onclick='modify_psw()'>修改密码</a></dd>" +
                "                        <dd><a onclick='user_quit()'>退出</a></dd>" +
                "                    </dl>" +
                "                </li>"
            $("#user-state").html(text)
        }
        element.render('header-user')
    }

    function user_quit() {
        sessionStorage.clear("userJson");
        location.href = '/exam_system/';
    }

    function modify_psw() {
    }

    function get_exam_result_by_eu_id() {
        layui.use(['layer', 'form'], function () {
            const layer = layui.layer;
            const form = layui.form;
            const eu_id = "${eu_id}";

            $.ajax({
                url: 'get_exam_result_by_eu_id',
                dataType: "json",//数据格式
                type: "post",//请求方式
                async: false,//是否异步请求
                data: {eu_id: eu_id},
                success: function (data) {
                    if (data.code === 200) {
                        cq_right_num = 0;
                        jq_right_num = 0;
                        saq_right_num = 0;
                        fbq_right_num = 0;
                        cq_score = 0;
                        jq_score = 0;
                        saq_score = 0;
                        fbq_score = 0;
                        $("#e_name").html("<i class=\"layui-icon layui-icon-spread-left\"></i>" + data.result.exam_res.exam.e_name);
                        var text = "";
                        for (let i = 0; i < data.result.scq_data.length; i++) {
                            text += "<div class=\"layui-col-sm12\" style=\"background: #f7f8fc\">" +
                                "                            <div class=\"layui-card\">"
                            var pr_cq_res = data.result.exam_res.paperResult.pr_cq_res.split(',')[i]
                            var cq_res = pr_cq_res.split('_')[1]
                            if (cq_res === data.result.scq_data[i].c_answer) {
                                text += "                                <div class=\"layui-card-header\" style='background: #a0ffb9'>" +
                                    "                                    单选题(" + data.result.exam_res.exam.e_scq_score + "分)" +
                                    "                                </div>";
                                cq_right_num += 1;
                            } else {
                                text += "                                <div class=\"layui-card-header\" style='background: #ff9696'>" +
                                    "                                    单选题(" + data.result.exam_res.exam.e_scq_score + "分)" +
                                    "                                </div>"
                            }
                            text += "                               <div class=\"layui-card-header\">" +
                                "                                       <xmp>" + (i + 1) + "." + data.result.scq_data[i].c_describe + "</xmp>" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-header\">" +
                                "                                        <xmp>A:" + data.result.scq_data[i].c_a + "</xmp>" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-header\">" +
                                "                                        <xmp>B:" + data.result.scq_data[i].c_b + "</xmp>" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-header\">" +
                                "                                        <xmp>C:" + data.result.scq_data[i].c_c + "</xmp>" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-header\">" +
                                "                                        <xmp>D:" + data.result.scq_data[i].c_d + "</xmp>" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-header\">正确答案:" +
                                "                                        " + data.result.scq_data[i].c_answer + "" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-header\">考生答案:" +
                                "                                        " + cq_res + "" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-body\">答案解析:" +
                                "" + data.result.scq_data[i].c_analysis + "" +
                                "                                    </div>" +
                                "                            </div>" +
                                "                        </div>";
                        }

                        for (let i = 0; i < data.result.jq_data.length; i++) {
                            text += "<div class=\"layui-col-sm12\" style=\"background: #f7f8fc\">" +
                                "                            <div class=\"layui-card\">"

                            var pr_jq_res = data.result.exam_res.paperResult.pr_jq_res.split(',')[i]
                            var jq_res = pr_jq_res.split('_')[1]
                            if (jq_res === data.result.jq_data[i].j_answer) {
                                text += "                                <div class=\"layui-card-header\" style='background: #a0ffb9'>" +
                                    "                                    判断题(" + data.result.exam_res.exam.e_jq_score + "分)" +
                                    "                                </div>";
                                jq_right_num += 1;
                            } else {
                                text += "                                <div class=\"layui-card-header\" style='background: #ff9696'>" +
                                    "                                    判断题(" + data.result.exam_res.exam.e_jq_score + "分)" +
                                    "                                </div>"
                            }

                            text += "                                <div class=\"layui-card-header\">" +
                                "                                    <xmp>" + (i + 1) + "." + data.result.jq_data[i].j_describe + "</xmp>" +
                                "                                </div>" +
                                "                                    <div class=\"layui-card-header\">正确答案:" +
                                "                                        " + data.result.jq_data[i].j_answer + "" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-header\">考生答案:" +
                                "                                        " + jq_res + "" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-body\">答案解析:" +
                                "" + data.result.jq_data[i].j_analysis + "" +
                                "                                    </div>" +
                                "                            </div>" +
                                "                        </div>";
                        }


                        for (let i = 0; i < data.result.fbq_data.length; i++) {
                            text += "<div class=\"layui-col-sm12\" style=\"background: #f7f8fc\">" +
                                "                            <div class=\"layui-card\" >"
                            var pr_fbq_res = data.result.exam_res.paperResult.pr_fbq_res.split(',')[i]
                            var fbq_res = pr_fbq_res.split('_')[1]
                            text += "                                <div class=\"layui-card-header\" style='background: gainsboro'>" +
                                "                                    填空题(" + data.result.exam_res.exam.e_fbq_score + "分)" +
                                "                                </div>"
                            text += "                                <div class=\"layui-card-header\">" +
                                "                                    <xmp>" + (i + 1) + "." + data.result.fbq_data[i].fb_describe + "</xmp>" +
                                "                                </div>" +
                                "                                    <div class=\"layui-card-body\">正确答案:" +
                                "<xmp>" + data.result.fbq_data[i].fb_answer + "</xmp>" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-body\">考生答案:" +
                                "" + fbq_res + "" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-body\">答案解析:" +
                                "" + data.result.fbq_data[i].fb_analysis + "" +
                                "                                    </div>" +
                                "                            </div>" +
                                "                        </div>";
                            fbq_right_num+=1
                            fbq_score +=Number(data.result.u_fbq_score_map[data.result.fbq_data[i].fb_id])
                        }

                        for (let i = 0; i < data.result.saq_data.length; i++) {
                            text += "<div class=\"layui-col-sm12\" style=\"background: #f7f8fc\">" +
                                "                            <div class=\"layui-card\" >"
                            var pr_saq_res = data.result.exam_res.paperResult.pr_saq_res.split('***')[i]
                            var saq_res = pr_saq_res.split('_')[1]
                            text += "                                <div class=\"layui-card-header\" style='background: gainsboro'>" +
                                "                                    简答题(" + data.result.exam_res.exam.e_saq_score + "分)" +
                                "                                </div>"
                            text += "                                <div class=\"layui-card-header\">" +
                                "                                    <xmp>" + (i + 1) + "." + data.result.saq_data[i].sa_describe + "</xmp>" +
                                "                                </div>" +
                                "                                    <div class=\"layui-card-body\">正确答案:" +
                                "" + data.result.saq_data[i].sa_answer + "" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-body\">考生答案:" +
                                "" + saq_res + "" +
                                "                                    </div>" +
                                "                                    <div class=\"layui-card-body\">答案解析:" +
                                "" + data.result.saq_data[i].sa_analysis + "" +
                                "                                    </div>" +
                                "                            </div>" +
                                "                        </div>";
                            saq_right_num+=1
                            saq_score +=Number(data.result.u_saq_score_map[data.result.saq_data[i].sa_id])
                        }
                        $("#cq_right_num").html(cq_right_num + "/" + data.result.scq_data.length);
                        cq_score = cq_right_num * data.result.exam_res.exam.e_scq_score;
                        $("#cq_score").html(cq_score);
                        $("#jq_right_num").html(jq_right_num + "/" + data.result.jq_data.length);
                        jq_score = jq_right_num * data.result.exam_res.exam.e_jq_score;
                        $("#jq_score").html(jq_score);

                        saq_right_num = saq_right_num * data.result.exam_res.exam.e_saq_score;
                        $("#saq_right_num").html(saq_right_num);
                        $("#saq_score").html(saq_score);

                        fbq_right_num = fbq_right_num * data.result.exam_res.exam.e_fbq_score;
                        $("#fbq_right_num").html(fbq_right_num);
                        $("#fbq_score").html(fbq_score);

                        $("#total_score").html(data.result.exam_res.exam.e_total_score);
                        $("#u_total_score").html(cq_score+jq_score+saq_score+fbq_score);
                        $("#question_list").html(text);
                    } else {

                    }
                },
                error: function (e) {
                    alert("出现错误！！");
                }
            });
        })
    }
</script>
</html>